<template>
  <div class="lookupTestDetailMain h100">
    <!-- 搜索区域 -->
    <div class="lookupTestDetailMainSearch">
      <lookup-test-detail-main-search
        :upgradeTaskId="upgradeTaskId"
        :strategy-id="strategyId"
        :version-type="versionType"
        :upgrade-trigger-type="upgradeTriggerType"
        @search="searchData"
        @sendSearchKey="searchKeyData"
        @export="exportTaskVehicle"
        :exporting="exporting"></lookup-test-detail-main-search>
    </div>
    <!-- 列表区域start -->
    <div class="lookupTestDetailMainLists">
      <lookup-test-detail-main-lists
        :upgradeTaskId="upgradeTaskId"
        :task-id="taskId"
        ref="lookupTestDetailMainListsRef"
        :type="type"
        :upgrade-trigger-type="upgradeTriggerType"
        :update="updateCount"
        :endTime="endTime"
        :vin="vin"
        :status="status"
        ></lookup-test-detail-main-lists>
    </div>
  </div>
</template>
<script>
import LookupTestDetailMainSearch from './LookupTestDetailMainSearch'
import LookupTestDetailMainLists from './LookupTestDetailMainLists'
import { mapState } from 'vuex'
import taskApi from '@/api/modules/task'
import { downloadBlobFile } from '@/utils/functions'
export default {
  components: {
    LookupTestDetailMainSearch,
    LookupTestDetailMainLists
  },
  props: {
    upgradeTaskId:{
      type: String,
      default: ''
    },
    endTime: {
      type: Number,
      default: undefined
    },
    strategyId: {
      type: String,
      default: ''
    },
    versionType: {
      type: String,
      default: ''
    },
    upgradeTriggerType: {
      type: String,
      default: ''
    },
    // 是sota测试任务8,fota测试任务9
    type: {
      type: Number,
      default: 9
    }
  },
  computed: {
    ...mapState({
      queryParams: (state) => state.strategy.taskVehicleQueryParams
    })
  },
  data () {
    return {
      // 是否正在导出任务车辆
      exporting: false,
      taskId: '',
      updateCount: 0,
      vin:'',
      status:undefined
    }
  },
  methods: {
    searchKeyData(vin,status){
      this.vin=vin
      this.status=status
    },
    searchData (taskId) {
      console.log(taskId, 'taskid')
      if (taskId === 'justUpdate') {
        this.updateCount = this.updateCount + 1
      } else {
        this.taskId = taskId
        console.log(taskId, 'taskId1')
        this.$emit('changetesttaskid', taskId)
      }
    },
    // 导出任务车辆
    exportTaskVehicle () {
      this.exporting = true
      taskApi.exportTaskCars({ taskId: this.taskId, type: 2, ...this.queryParams }).then(res => {
        downloadBlobFile(res, 'task-vehicle.xlsx')
      }).finally(() => {
        this.exporting = false
      })
    }
  }
}
</script>
<style lang="less" scoped>
.lookupTestDetailMain {
  display: flex;
  flex-direction: column;
  .lookupTestDetailMainSearch {
    flex:none;
  }
  .lookupTestDetailMainLists {
    flex:1 0 0;
    overflow: auto;
    margin-top: 15px;
  }
}
</style>
